﻿using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Security;

namespace Songhay.Silverlight.BiggestBox.IndexPart.ViewModels
{
    using Songhay.Models;
    using Songhay.Mvvm.ViewModels;

    /// <summary>
    /// OS data
    /// </summary>
    public class ReportOSViewModel : ViewModelBase
    {
        /// <summary>
        /// Gets the environment variables.
        /// </summary>
        /// <value>The environment variables.</value>
        public ObservableCollection<SystemVariable> EnvironmentVariables
        {
            get
            {
                var list = new ObservableCollection<SystemVariable>();

                var variableName = string.Empty;
                var variableDescription = string.Empty;
                var variableValue = string.Empty;

                #region Insert data into list:

                //variableName = "MachineName";
                //variableDescription = "Network Identification";
                //variableValue = Environment.MachineName;
                //list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                variableName = "OSVersion.Platform";
                variableDescription = "Operating System Platform";
                variableValue = Environment.OSVersion.Platform.ToString();
                list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                //variableName = "OSVersion.ServicePack";
                //variableDescription = "Operating System Service Pack";
                //variableValue = Environment.OSVersion.ServicePack;
                //list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                //variableName = "OSVersion.VersionString";
                //variableDescription = "Operating System Version Summary";
                //variableValue = Environment.OSVersion.VersionString;
                //list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                //variableName = "UserDomainName";
                //variableDescription = "User Domain Name";
                //variableValue = Environment.UserDomainName;
                //list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                //variableName = "UserName";
                //variableDescription = "User Name";
                //variableValue = Environment.UserName;
                //list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                variableName = "Version.Major";
                variableDescription = "CLR Major Version";
                variableValue = Environment.Version.Major.ToString();
                list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                //variableName = "Version.MajorRevision";
                //variableDescription = "CLR Major Revision";
                //variableValue = Environment.Version.MajorRevision.ToString();
                //list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                variableName = "Version.Minor";
                variableDescription = "CLR Minor Version";
                variableValue = Environment.Version.Minor.ToString();
                list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                //variableName = "Version.MinorRevision";
                //variableDescription = "CLR Minor Revision";
                //variableValue = Environment.Version.MinorRevision.ToString();
                //list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                variableName = "Version.Revision";
                variableDescription = "CLR Revision";
                variableValue = Environment.Version.Revision.ToString();
                list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });

                //try
                //{
                //    foreach(DictionaryEntry environment in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine))
                //    {
                //        variableName = string.Format("EnvironmentVariableTarget.Machine [key: {0}]", environment.Key);
                //        variableDescription = "Machine Environment Variables";
                //        variableValue = environment.Value.ToString();
                //        list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });
                //    }

                //}
                //catch(SecurityException ex)
                //{
                //    variableName = "EXCEPTION for EnvironmentVariableTarget.Machine";
                //    variableDescription = string.Empty;
                //    variableValue = string.Format("Message: {0}\nGranted Set: {1}\nPermission State: {2}\nRefused State: {3}", ex.Message, ex.GrantedSet, ex.PermissionState, ex.RefusedSet);
                //    list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });
                //}

                //try
                //{
                //    foreach(DictionaryEntry environment in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process))
                //    {
                //        variableName = string.Format("EnvironmentVariableTarget.Process [key: {0}]", environment.Key);
                //        variableDescription = "Process Environment Variables";
                //        variableValue = environment.Value.ToString();
                //        list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });
                //    }
                //}
                //catch(SecurityException ex)
                //{
                //    variableName = "EXCEPTION for EnvironmentVariableTarget.Process";
                //    variableDescription = string.Empty;
                //    variableValue = string.Format("Message: {0}\nGranted Set: {1}\nPermission State: {2}\nRefused State: {3}", ex.Message, ex.GrantedSet, ex.PermissionState, ex.RefusedSet);
                //    list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });
                //}

                //try
                //{
                //    foreach(DictionaryEntry environment in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User))
                //    {
                //        variableName = string.Format("EnvironmentVariableTarget.User [key: {0}]", environment.Key);
                //        variableDescription = "User Environment Variables";
                //        variableValue = environment.Value.ToString();
                //        list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });
                //    }
                //}
                //catch(SecurityException ex)
                //{
                //    variableName = "EXCEPTION!";
                //    variableDescription = "EXCEPTION for EnvironmentVariableTarget.User";
                //    variableValue = string.Format("Message: {0}\nGranted Set: {1}\nPermission State: {2}\nRefused State: {3}", ex.Message, ex.GrantedSet, ex.PermissionState, ex.RefusedSet);
                //    list.Add(new SystemVariable { VariableName = variableName, VariableDescription = variableDescription, VariableValue = variableValue });
                //}

                #endregion

                return list;
            }
        }

        /// <summary>
        /// Gets the header text.
        /// </summary>
        /// <value>The header text.</value>
        public string HeaderText
        {
            get { return string.Concat("About This Machine: ", "Environment.MachineName"); }
        }
    }
}
